package com.onlylemi.mapview;

import com.onlylemi.mapview.library.utils.MapUtils;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.utils.Point;
import ohos.media.image.PixelMap;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class ExampleOhosTest {
    @Test
    public void getDistanceBetweenList() {
        List<Point> nodes = new ArrayList<>();
        nodes.add(new Point(100, 100));
        nodes.add(new Point(400, 500));
        List<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        float distance = MapUtils.getDistanceBetweenList(nodes, list);
        assertEquals(500, distance, 0);
    }

    @Test
    public void getShortestPathBetweenTwoPoints() {
        List<Point> nodes = new ArrayList<>();
        nodes.add(new Point(100, 100));
        nodes.add(new Point(100, 200));
        nodes.add(new Point(100, 100));
        nodes.add(new Point(100, 200));
        List<Point> nodesContact = new ArrayList<>();
        List<Integer> result = MapUtils.getShortestPathBetweenTwoPoints(0, 3, nodes, nodesContact);
        List<Integer> expected = new ArrayList<>();
        expected.add(0);
        expected.add(3);
        assertEquals(expected, result);
    }

    @Test
    public void getDegreeBetweenTwoPointsWithHorizontal() {
        List<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        List<Point> nodes = new ArrayList<>();
        nodes.add(new Point(100, 100));
        nodes.add(new Point(100, 200));
        List<Float> result = MapUtils.getDegreeBetweenTwoPointsWithHorizontal(list, nodes);
        List<Float> expected = new ArrayList<>();
        expected.add(90f);
        assertEquals(expected, result);
    }

    @Test
    public void getDegreeBetweenTwoPointsWithVertical() {
        List<Integer> list = new ArrayList<>();
        list.add(0);
        list.add(1);
        List<Point> nodes = new ArrayList<>();
        nodes.add(new Point(100, 100));
        nodes.add(new Point(100, 200));
        List<Float> result = MapUtils.getDegreeBetweenTwoPointsWithVertical(list, nodes);
        List<Float> expected = new ArrayList<>();
        expected.add(180f);
        assertEquals(expected, result);
    }

    @Test
    public void getShortestDistanceBetweenTwoPoints() {
        List<Point> nodes = new ArrayList<>();
        nodes.add(new Point(100, 100));
        nodes.add(new Point(100, 200));
        List<Point> nodesContact = new ArrayList<>();
        float result = MapUtils.getShortestDistanceBetweenTwoPoints(0, 1, nodes, nodesContact);
        assertEquals(100f, result, 0);
    }

    @Test
    public void getPixelMap() {
        PixelMap result = MapUtils.getPixelMap(MyApplication.getInstance(), ResourceTable.Media_map);
        assertNotNull(result);
    }
}